#!/usr/local/php/bin/php
<?php
namespace fky\cli;
/*使用linux的crontab配置定时任务*/

// fix for fcgi
defined('STDIN') or define('STDIN', fopen('php://stdin', 'r'));

require_once '..'.DIRECTORY_SEPARATOR.'FkyLoad.php';
//定义项目根目录
define('FKY_PROJECT_PATH',  __DIR__ .DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);

//date_default_timezone_set('PRC');
//loadc('db',loadc('config')->get("db", "config"));
//loadc('loader')->run();
//初始化配置参数
//php命令
$phpPath = loadc('config')->get("php", "cron");
//项目目录
$projectPath = FKY_PROJECT_PATH;
//进程运行角色
$uid = loadc('config')->get("user", "cron");

//定制任务配置
//# Example of job definition:
//# .---------------- minute (0 - 59)
//# |  .------------- hour (0 - 23)
//# |  |  .---------- day of month (1 - 31)
//# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
//# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
//# |  |  |  |  |
//# *  *  *  *  * user-name  command to be executed
//*/1 * * * * {$uid} {$phpPath} {$projectPath}fky/cli/fkycmd test2 test2  &>> {$projectPath}data/log/crond.log
//*/1 * * * * root {$projectPath}fky/cli/crond.sh start &>> {$projectPath}data/log/crond.log

$options = getopt('d');
if (isset($options['d'])) { //清空定时任务
    $crontab = '';
} else {
$crontab = <<< EOT
#每分钟尝试启动一次swoole定时任务
*/1 * * * * root {$projectPath}fky/cli/crond.sh start &>> {$projectPath}data/log/crond.log
EOT;
}

//安装定时任务
loadf('installCrontab');
